package BlackJack.Model.VO
{

	public class TableData
	{
		private var _Index:int;
		private var _MaxPoint:int;
		private var _MinPoint:int;
		private var _ViewerCount:int;
		private var _JoinLinkBonus:int;
		private var _TableName:String;
		private var _LimitMaxPoint:int;
		private var _LimitMinPoint:int;
		private var _ModelNo:Vector.<int>                 = new Vector.<int>(5);
		private var _ID:Vector.<String>                   = new Vector.<String>(5);
		private var _Nickname:Vector.<String>             = new Vector.<String>(5);
		private var _DispPlayer:Vector.<int>              = new Vector.<int>(5);
		private var _PlayerBet:Vector.<int>               = new Vector.<int>(3);
		private var _ViewBet:Vector.<int>                 = new Vector.<int>(3);
		private var _PlayerCount:int;
		private var _PlayerMax:int;
		public var Banker:Vector.<uint>                   = Vector.<uint>([]);
		public var Player:Vector.<Vector.<Vector.<uint>>> = new Vector.<Vector.<Vector.<uint>>>(5);
		public var type:int                               = -1;
		public var spotLight:int                          = -1;

		public function TableData()
		{
			for (var i:int = 0; i < 5; i++)
			{
				Player[i] = new Vector.<Vector.<uint>>(2);
				Player[i][0] = Vector.<uint>([]);
				Player[i][1] = Vector.<uint>([]);
			}
		}

		public function set D(value:String):void
		{
			Banker = ParseArray(value);
		}

		public function set V1(value:int):void
		{
			_Index = value;
			if (value >= 90)
			{
				_PlayerMax = 1;
			}
			else
			{
				_PlayerMax = 5;
			}
		}

		public function set V2(value:int):void
		{
			_MaxPoint = value;
		}

		public function set V3(value:int):void
		{
			_MinPoint = value;
		}

		public function set V4(value:int):void
		{
			_ViewerCount = value;
		}

		public function set V5(value:int):void
		{
			_JoinLinkBonus = value;
		}

		public function set V6(value:String):void
		{
			_TableName = value;
		}

		public function set V7(value:int):void
		{
			_LimitMaxPoint = value;
		}

		public function set V8(value:int):void
		{
			_LimitMinPoint = value;
		}

		public function set M0(value:int):void
		{
			_ModelNo[0] = value;
		}

		public function set M1(value:int):void
		{
			_ModelNo[1] = value;
		}

		public function set M2(value:int):void
		{
			_ModelNo[2] = value;
		}

		public function set M3(value:int):void
		{
			_ModelNo[3] = value;
		}

		public function set M4(value:int):void
		{
			_ModelNo[4] = value;
		}

		public function set D0(value:int):void
		{
			_DispPlayer[0] = value;
		}

		public function set D1(value:int):void
		{
			_DispPlayer[1] = value;
		}

		public function set D2(value:int):void
		{
			_DispPlayer[2] = value;
		}

		public function set D3(value:int):void
		{
			_DispPlayer[3] = value;
		}

		public function set D4(value:int):void
		{
			_DispPlayer[4] = value;
		}

		public function set N0(value:String):void
		{
			_Nickname[0] = value;
		}

		public function set N1(value:String):void
		{
			_Nickname[1] = value;
		}

		public function set N2(value:String):void
		{
			_Nickname[2] = value;
		}

		public function set N3(value:String):void
		{
			_Nickname[3] = value;
		}

		public function set N4(value:String):void
		{
			_Nickname[4] = value;
		}

		public function set I0(value:String):void
		{
			_ID[0] = value;
		}

		public function set I1(value:String):void
		{
			_ID[1] = value;
		}

		public function set I2(value:String):void
		{
			_ID[2] = value;
		}

		public function set I3(value:String):void
		{
			_ID[3] = value;
		}

		public function set I4(value:String):void
		{
			_ID[4] = value;
		}

		public function set B0(value:int):void
		{
			_PlayerBet[0] = value;
		}

		public function set B1(value:int):void
		{
			_PlayerBet[1] = value;
		}

		public function set B2(value:int):void
		{
			_PlayerBet[2] = value;
		}

		public function set B3(value:int):void
		{
			_ViewBet[0] = value;
		}

		public function set B4(value:int):void
		{
			_ViewBet[1] = value;
		}

		public function set B5(value:int):void
		{
			_ViewBet[2] = value;
		}

		public function set X0(value:String):void
		{
			Player[0][0] = ParseArray(value);
		}

		public function set X1(value:String):void
		{
			Player[1][0] = ParseArray(value);
		}

		public function set X2(value:String):void
		{
			Player[2][0] = ParseArray(value);
		}

		public function set X3(value:String):void
		{
			Player[3][0] = ParseArray(value);
		}

		public function set X4(value:String):void
		{
			Player[4][0] = ParseArray(value);
		}

		public function set Y0(value:String):void
		{
			Player[0][1] = ParseArray(value);
		}

		public function set Y1(value:String):void
		{
			Player[1][1] = ParseArray(value);
		}

		public function set Y2(value:String):void
		{
			Player[2][1] = ParseArray(value);
		}

		public function set Y3(value:String):void
		{
			Player[3][1] = ParseArray(value);
		}

		public function set Y4(value:String):void
		{
			Player[4][1] = ParseArray(value);
		}

		public function set PlayerCount(value:int):void
		{
			_PlayerCount = value;
		}

		public function get Index():int
		{
			return _Index;
		}

		public function get MaxPoint():int
		{
			return _MaxPoint;
		}

		public function get MinPoint():int
		{
			return _MinPoint;
		}

		public function get ViewerCount():int
		{
			return _ViewerCount;
		}

		public function get JoinLinkBonus():int
		{
			return _JoinLinkBonus;
		}

		public function get TableName():String
		{
			return _TableName;
		}

		public function get LimitMaxPoint():int
		{
			return _LimitMaxPoint;
		}

		public function get LimitMinPoint():int
		{
			return _LimitMinPoint;
		}

		public function get ModelNo():Vector.<int>
		{
			return _ModelNo;
		}

		public function get DispPlayer():Vector.<int>
		{
			return _DispPlayer;
		}

		public function get Nickname():Vector.<String>
		{
			return _Nickname;
		}

		public function get ID():Vector.<String>
		{
			return _ID;
		}

		public function get PlayerBet():Vector.<int>
		{
			return _PlayerBet;
		}

		public function get ViewBet():Vector.<int>
		{
			return _ViewBet;
		}

		public function get PlayerCount():int
		{
			return _PlayerCount;
		}

		public function get PlayerMax():int
		{
			return _PlayerMax;
		}

		public static function Parse(src:String):TableData
		{
			var result:TableData = new TableData();
			var temp:Array       = src.split(']');
			var s:String         = temp[1];
			var infos:Array      = s.split('\n');
			var info:String;
			var array:Array;
			for each (info in infos)
			{
				array = info.split('=');
				result[array[0]] = array[1];
			}
			var count:int = 0;
			for each (var id:String in result.ID)
			{
				if (id.length > 0)
				{
					count++;
				}
			}
			result.PlayerCount = count;
			return result;
		}

		public static function ParseArray(value:String):Vector.<uint>
		{
			var array:Array          = value.split(',');
			var len:int              = array.length;
			var result:Vector.<uint> = Vector.<uint>([]);
			for (var i:int = 0; i < len; i++)
			{
				if (array[i] > 0)
				{
					result.push(array[i]);
				}
			}
			return result;
		}

		public static function NumberToString(src:int):String
		{
			var base:String   = src.toString();
			var len:int       = base.length;
			var result:String = '';
			while (len > 0)
			{
				if (len > 3)
				{
					result = ',' + base.substr(len - 3, 3) + result
					base = base.substr(0, len - 3);
				}
				else
				{
					result = base + result;
					base = '';
				}
				len = base.length;
			}
			return result;
		}
	}
}
